﻿#region 命名空间

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.ControlPanel
{
    [Access("265003")]
    public partial class WinnerCMSEmailSetting : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    ReadMailConfigXML();
                }
                catch (Exception Ex)
                {
                    MsgBox.Message(Ex.Message.Replace(@"\", @"\\"), this.UpdatePanel1);
                }
            }
        }

        #region eMail

        private void ReadMailConfigXML()
        {
            var config = CMSConfig.Instance();
            this.cbkMailSend.Checked = config.EMail.IsSend;
            this.txtMailFrom.Text = config.EMail.From;
            this.txtMailFromName.Text = config.EMail.FromName;
            this.txtMailDomain.Text = config.EMail.Domain;
            this.txtMailServerUserName.Text = config.EMail.UserName;
            this.txtMailServerPassWord.Text = config.EMail.PassWord;
        }

        private void WriteMailConfigXML()
        {
            var config = CMSConfig.Instance();
            config.EMail.IsSend = this.cbkMailSend.Checked;
            config.EMail.From = this.txtMailFrom.Text;
            config.EMail.FromName = this.txtMailFromName.Text;
            config.EMail.Domain = this.txtMailDomain.Text;
            config.EMail.UserName = this.txtMailServerUserName.Text;
            config.EMail.PassWord = this.txtMailServerPassWord.Text;
            config.Save(config);
        }

        #endregion

        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                WriteMailConfigXML();
            }
            catch (Exception Ex)
            {
                MsgBox.Message(Ex.Message.Replace(@"\", @"\\"), this.UpdatePanel1);
            }
        }
    }
}